#region Using

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;

using Gizmox.WebGUI.Common;
using Gizmox.WebGUI.Forms;

#endregion

namespace VisualDB
{
    public partial class RenameForm : Form
    {
        private RenameType _renameType;
        private string _oldName;

        public RenameForm(string title, RenameType renameType, string name)
        {
            InitializeComponent();

            this.Text = title;
            _renameType = renameType;
            _oldName = name;
            this.txtName.Text = name;
        }

        public RenameType RenameType
        {
            get
            {
                return _renameType;
            }
        }

        public string NewName
        {
            get
            {
                return this.txtName.Text;
            }
        }

        public string OldName
        {
            get
            {
                return _oldName;
            }
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            if (this.txtName.Text.ToLower() != this.OldName.ToLower())
            {
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            else
            {
                MessageBox.Show("New name must be different!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }

        private void RenameForm_Load(object sender, EventArgs e)
        {
            this.txtName.Focus();
            this.txtName.SelectAll();
        }

        private void txtName_KeyDown(object objSender, KeyEventArgs objArgs)
        {
            if (objArgs.KeyCode == Keys.Enter)
            {
                btnOk_Click(objSender, EventArgs.Empty);
            }
            else if (objArgs.KeyCode == Keys.Escape)
            {
                btnCancel_Click(objSender, EventArgs.Empty);
            }
        }
    }

    public enum RenameType
    {
        Table,
        View,
        StoredProcedure
    }
}